%% LoadData
% Loads data from a variety of sources
%% Rights and disclaimer
% Author: Benjamin J. J. Voigt (bvoigt@gmail.com)
% Published: Oct 2012
% Version: 0.0.1
% License: BSD 2-Clause, free to use and copy retaining original author reference
% 
% Disclaimer: USE AT YOUR OWN RISK; NO INVESTMENT RECOMMENDATION IMPLIED;
% NOT ASSOCIATED WITH PAST, CURRENT OR FUTURE EMPLOYER OR ASSOCIETES OF THE
% AUTHOR; DO NOT USE THIS CODE TO INVEST YOUR OWN MONEY OR TO 
% ENCOURAGE OTHERS TO INVEST MONEY;
%% Syntax
% aaa
%% Arguments
% bbb
%% Examples
% ccc
%% Required toolboxes
% Financial Toolbox, Data Feed Toolbox, Statistics
% Toolbox
%% Purpose and notes
% Purpose: Load data from Yahoo, local database or data vendor
%
% Notes: --
%
% Known limitations:
% 1) Incomplete load method set, i.e., no db connection
% 2) only allows for one field and symbol to be retrieved, resulting in
% slow query speed as yahoo object is recreated for each call
% 3) only one of the yahoo parameter t8, Target price is implemented
%
function [return_cell] = LoadData(load_method_str, symbol_str, field_str, start_date_str, end_date_str, frequency_str)
% Global, function wide variables 
g_load_method = load_method_str;
g_symbol_str = symbol_str;
g_field_str = field_str;
g_start_date_str = start_date_str;
g_end_date_str =end_date_str;
g_frequency_str = frequency_str;
g_connect_datafeed = yahoo;

% Local, dummy, loop or sub-section specific variables
l_dummy = 0;

switch g_load_method
    case 'datafeed_full'
        return_cell = fetch(g_connect_datafeed, g_symbol_str, g_field_str,...
            g_start_date_str,g_end_date_str, g_frequency_str)
    case 'datafeed_last'
        l_dummy = fetch(g_connect_datafeed, g_symbol_str)
        return_cell = num2str(l_dummy.Last)
    case 'yql'
        switch g_field_str
            case 'Target price'
                return_cell = urlread(char(strcat(...
                'http://download.finance.yahoo.com/d/quotes.csv?s=',...
                g_symbol_str,'&f=t8')))
            otherwise
                %TODO: error message
                ;
        end
    case 'db'
    case 'file'
    otherwise
        %TODO: error message
        ;
end